package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.food.dao.service.CollectService;
import com.food.dao.service.MemberService;
import com.food.dao.service.OrderService;
import com.food.dao.service.RecipeService;
import com.food.model.Collect;
import com.food.model.Member;
import com.food.model.Order;
import com.food.model.Recipe;

@WebServlet("/member/MyOrder")
public class MyOrder extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		OrderService service = new OrderService();
		MemberService memberService = new MemberService();
		
		HttpSession session = request.getSession();
		Member member = (Member)session.getAttribute("user");
		
		Order order = new Order();
		order.setMymbid(member.getMbid());
		List<Order> list = service.findOrderByMb(order);
		List<Member> coll = new ArrayList<Member>();
		for(Order od:list){
			Member his = new Member();
			his.setMbid(od.getHismbid());
			his = memberService.findMember(his);
			coll.add(his);
			
		}
		request.setAttribute("mbOrder", coll);
		RequestDispatcher rd = request
				.getRequestDispatcher("/member/myorder.jsp");
		rd.forward(request, response);
		return;
	}
	

}
